package hkr.se1.cyvasse;

import Game.Game;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class TileView extends RelativeLayout {

	private ImageView tile;
	private ImageView piece;
	private ImageView shader;
	private ImageView cover;

	public TileView(Context context, Game game) {
		super(context);
		init(context, game);
	}

	private void init(Context context, Game game) {

		tile = new ImageView(context);
		piece = new ImageView(context);
		shader = new ImageView(context);
		cover = new ImageView(context);

		
		
		
		addView(tile);
		addView(shader);
		addView(piece);
		addView(cover);

		float transparency = (float) 0.5;
		shader.setAlpha(transparency);

		setOnDragListener(new MyDragListener(game));
		setOnTouchListener(new MyTouchListener(game));
	}

	public void setPieceImage(int imageID) {
		piece.setImageResource(imageID);
	}

	public void setPieceDrawable(Drawable drawable) {
		piece.setImageDrawable(drawable);
	}

	public Drawable getPieceImage() {
		return piece.getDrawable();
	}

	public void setTileImage(int imageID) {
		tile.setImageResource(imageID);
	}

	public void setTileDrawable(Drawable image) {
		tile.setImageDrawable(image);
	}

	public Drawable getTileImage() {
		return tile.getDrawable();
	}

	public View getTileView() {
		return tile;
	}

	public void clearPieceDrawable() {
		piece.setImageDrawable(null);
	}

	public View getPieceView() {
		return piece;
	}

	public void setShader(int type) {
		switch (type) {
		case (Game.MOVE):
			shader.setImageResource(hkr.se1.cyvasse.R.drawable.move_image);
			break;
		case (Game.ATTACK):
			shader.setImageResource(hkr.se1.cyvasse.R.drawable.attack_image);
			break;
		case (Game.MOVE_ATTACK):
			shader.setImageResource(hkr.se1.cyvasse.R.drawable.attack_image);
			break;
		default:
			shader.setImageDrawable(null);
			break;
		}
	}

	public void setCoverVisibility(boolean visibility) {
		if (visibility) {
			cover.setImageResource(R.drawable.hide_tile);
		} else {
			cover.setImageDrawable(null);
		}
	}
}
